<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

        div {
            width: 200px;
            height: 200px;
            border: 1px solid #000;
            margin: auto;
        }

        section{
            width: 500px;
            height: 500px;
            border: 1px solid #000;
            margin: auto;
            position: relative;
        }
    </style>
</head>
<body>


    <section>
        <div></div>
    </section>


    <script>

        // offsetLeft / offsetTop   距离最近的具有定位的祖先元素的左边距或上边距 ， div本身不需要有定位



        var oDiv = document.querySelector('div') ;

        console.log(oDiv.offsetLeft);

    </script>
    
</body>
</html>